package recursion;

import java.util.Arrays;

public class FullPermutation {
    public static void main(String[] args) {
        int[] arr = {1,2,3};
        fullPermutation(arr,0);
    }

//    public static void fullPermutation(int[] arr) {
//        fullPermutation(arr, 0);
//    }
//
//    public static void fullPermutation(int[] arr,int start) {
//        if (start == arr.length - 1) {   //--------------------start == arr.length-1  start == arr.length 都可以
//            System.out.println(Arrays.toString(arr));
//            return;
//        }
//        for (int i = start; i < arr.length; i++) { //---------------------i=start   不是i=0
//            swap(arr, i, start);
//            fullPermutation(arr, start + 1);
//            swap(arr, i, start);
//        }
//    }
//    public static void swap(int[] arr,int a,int b) {  //--------------不需要返回值
//        int temp = arr[a];
//        arr[a] = arr[b];
//        arr[b] = temp;
//    }

    public static void fullPermutation(int[] arr,int start) {
        if (start == arr.length - 1) {
            System.out.println(Arrays.toString(arr));
        }
        for (int i = start; i < arr.length; i++) {
            swap(arr, i, start);
            fullPermutation(arr, start + 1);
            swap(arr, i, start);
        }
    }
    public static void swap(int[] arr,int i,int start) {
        int temp = arr[i];
        arr[i] = arr[start];
        arr[start] = temp;
    }


}
